<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>																			
<%@ include file="/WEB-INF/view/jsp/base.jsp" %>																																			
<html lang="en">
<head>
<style>
	.width{width: 206px;}
	input{-moz-box-sizing: border-box; }
</style>
</head>																																												
<body class="wysihtml5-supported">																																							
	<div id="content">																																										
		<div class="container-fluid">																																							
			<div class="row-fluid">																																							
				<div class="span12">																																							
					<div class="widget-box">																																					
						<div class="widget-title">																																			
							<h5>表单</h5>																																							
						</div>																																									
						<div class="widget-content nopadding">																																
							<form id="${lowerClassName}Form" action="" method="post" class="form-horizontal">																					
							<#--  定义一个是否换行标识,newLine==true的时候重新趋起一行，否则追加  -->
							<#assign newLine="true">
							<#list columns as col>
								<#--  列长度 ，列长度大于100的时候独立起一行 -->
								<#assign length=col.columnLength>
								<#if (length > 28) >
							      <#if newLine!="true">
									</div>	
								  </#if>
									<div class="flexbox">																																
							    <#else>
							      <#if newLine=="true">
									<div class="flexbox">																																
								  </#if>
							    </#if>
							    		<div class="flex-item">	
											<label>${col.columnComments} :</label>																															
									<#if length<=62>	
										<#switch col.dataType!"">
											<#case "DATE">
											   	<input <#list uniqueIndex.fieldNames as unique><#if unique=col.fieldName> primaryKey="true" </#if></#list> type="text" class="date" name="${col.fieldName}" placeholder="" style="width:${10*12}px;" size="10"  maxlength="10">
											   <#break>
											<#case "SELECT">
												<select <#list uniqueIndex.fieldNames as unique><#if unique=col.fieldName> primaryKey="true" </#if></#list>  class="" name="${col.fieldName}" placeholder=""   maxlength="${col.columnLength}">
												<#if col.options??>
													<#list col.options as op>
														<#if op??>
															<#list op?keys as key>
													<option value="${key}">${op[key]}</option>
															</#list>
														</#if>
													</#list>
												</#if>
												</select>
											   <#break>
											<#case "AMOUNT">
											  	<input <#list uniqueIndex.fieldNames as unique><#if unique=col.fieldName> primaryKey="true" </#if></#list> type="text" class="moneyNum " style="text-align:right;width:${length*12}px;" name="${col.fieldName}" value="0.00" placeholder="0.00" size="${col.columnLength}"  maxlength="${col.columnLength}">
											   <#break>
											<#case "INTEGER">
											  	<input <#list uniqueIndex.fieldNames as unique><#if unique=col.fieldName> primaryKey="true" </#if></#list> type="text" class="" style="text-align:right;width:${length*14}px;"  name="${col.fieldName}" value="0" placeholder="" size="${col.columnLength}"  maxlength="${col.columnLength}">
											   <#break>
											<#default>
												<input <#list uniqueIndex.fieldNames as unique><#if unique=col.fieldName> primaryKey="true" </#if></#list> type="text" class="" name="${col.fieldName}" placeholder="" size="${col.columnLength}"  maxlength="${col.columnLength}">
										</#switch>
									<#else><#-- 当字条串的长度大于62位的时候，使用textarea文本域控件 -->
										    	<textarea type="text" class="" name="paraDesc" placeholder="" style="width:${62*14}px;" size="${length}"  maxlength="${length}"></textarea>
									</#if>
												<span class="error_msg" name="error_${col.fieldName}"></span>
										</div>		
								<#if (length > 28) >
									</div>
									<#assign newLine="true">
							    <#else>
							      <#if newLine!="true">
									</div>	
									<#assign newLine="true">
								  <#else>
								  	<#assign newLine="false">
								  </#if>
							    </#if>
							</#list>																																							
								<div class="form-actions">																																	
									<button id="id_add" type="button" class="btn btn-success f-right"  style="float:right;margin-left:10px;" onclick="save()">保存</button>											 
 									<button id="id_cancel" type="button" class="btn btn-info f-right"  style="float:right;margin-left:10px;" onclick="cancle()">取消</button>	
								</div>																																							
							</form>																																								
						</div>																																									
					</div>																																										
				</div>																																											
			</div>																																												
		</div>																																													
	</div>		
			<div id="modelDialog" class="modal hide fade in" style="display:none;">
		<div class="modal-header">
			<a class="close" data-dismiss="modal">x</a>
			<h4>操作提示</h4>
		</div>
		<div class="modal-body">
			<h4>确认删除该项记录吗？</h4>
		</div>
		<div class="modal-body">
			<button id="confirm" type="button" class="btn btn-success">确认</button>
			<button  type="button class="btn btn-default" data-dismiss="modal">关闭</button>
		</div>
	</div>																																													
	<script>																																													
	    var params = mainParam.param;   //接收传来的参数																																							
	    var _pageNum = "" ;  //接收list页面传来的当面页数																																				
		//初始化表单数据																																												
		${r'$'}(document).ready(function(){																																							
			${r'$'}('.date').datetimepicker({
				language:'zh-CN',
				format:'yyyy-mm-dd',
				minView:"month",
				initialDate:new Date(),
				autoclose:true,
				todayBtn:true
			});
			
			_pageNum = "${r'$'}{param.pageNum}" ;																																					
			if(!${r'$'}.isEmptyObject(params)){																																						
				${r'$'}("input[primaryKey='true']").attr("readonly","readonly");																												
				$("#id_cancel").css("display","block");
				${r'$'}.ajax({																																										
					url:"<%=path%>/${lowerClassName}/get",																																			
				    data:params,																																						
				    type:"post",																																								
				    success:function(text){																																						
				    	if(text.success){																																						
				    		${r'$'}("${r'#'}${lowerClassName}Form").autofill(text.data);																															
				    	}																																										
				    }																																											
				});																																												
			}																																													
		});																																														
		//保存表单数据																																												
		function save(){																																										
			var _editType = null ;																																								
			if(!${r'$'}.isEmptyObject(params)){																																						
				_editType = "edit";																																							
				${r'$'}("${r'#'}${lowerClassName}Form").prop("action","<%=path %>/${lowerClassName}/update");																					
			}else{																																												
				_editType = "add";																																							
				${r'$'}("${r'#'}${lowerClassName}Form").prop("action","<%=path %>/${lowerClassName}/add");																						
			}																																													
			//保存																																												
			${r'$'}("${r'#'}${lowerClassName}Form").ajaxSubmit(function(text){																															
			    C.handleError(${r'$'}("${r'#'}${lowerClassName}Form"),text.error);
			    C.gritter(text.message);
			    if(text.success){																																								
			    	if(_editType == "edit"){																																					
			    		cancle(); //返回原页面																																			
			    	}else if(_editType == "add"){																																				
						var $form = ${r'$'}("${r'#'}${lowerClassName}Form");
						toLoad("<%=path %>/${lowerClassName}/detail",$form.serialize());																																					
			    	}																																											
				}																																												
			});																																													
		}		
		
		
		//输入金额类型数据
		${r'$'}(".moneyNum").keyup(function(){
			var reg=${r'$'}(this).val().match(/\d+\.?\d{0,2}/);
			var txt = '';
			if(reg!=null){
				txt=reg[0];
			}
			${r'$'}(this).val(txt);
		}).change(function(){
			${r'$'}(this).keypress();
			var v=${r'$'}(this).val();
			if(/\.${r'$'}/.test(v)){
				${r'$'}(this).val(v.substr(0,v.length-1));
			}
		})
		
																																														
	</script>																																													
</body>																																														
 </html>	    																																												

